package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.commom.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;


    @Override
    public void deleteById(Integer id){
        roleMapper.deleteById(id);
    }


    @Override
    public void addRole(Role role){
        roleMapper.insert(role);
    }

    @Override
    public Role getById(Integer id){
        return roleMapper.getById(id);
    }

    @Override
    public void update(Role role){
        roleMapper.update(role);
    }
    @Override
    public Object listAll(Integer status){
        return roleMapper.listAll();
    }

    @Override
    public PageResult<Role> listRoles(String name, String label, Integer page, Integer pageSize){
        PageHelper.startPage(page, pageSize);
        List<Role> roles = roleMapper.listRoles(name, label);
        Page<Role> rolePage = (Page<Role>) roles;
        return new PageResult<>(rolePage.getTotal(), rolePage.getResult());
    }






}
